<template>
  <div class="app-container">
    <Pagetitle :title="pageTitle.title"></Pagetitle>
    <div class="table-container min-height">
      <Row class="password-box">
        <Col
          span="8"
          offset="6"
        >
        <Form
          ref="updataPasswordData"
          :model="updataPasswordData"
          :rules="rulePassword"
          :label-width="80"
        >
          <FormItem
            label="旧密码"
            prop="oldPassword"
          >
            <Input
              type="password"
              v-model="updataPasswordData.oldPassword"
            ></Input>
          </FormItem>
          <FormItem
            label="新密码"
            prop="newPassword"
          >
            <Input
              type="password"
              v-model="updataPasswordData.newPassword"
            ></Input>
          </FormItem>
          <FormItem>
            <Button
              type="primary"
              @click="handleSubmitRegister('updataPasswordData')"
            >确认修改</Button>
          </FormItem>
        </Form>
        </Col>
      </Row>
      <div class="password-box">

      </div>
    </div>
  </div>
</template>
<script>
import { register } from "@/api/other";
import { Pagetitle, BrandItem } from "@/components";
export default {
  data() {
    return {
      pageTitle: {
        title: "修改密码"
      },
      updataPasswordData: {
        oldPassword: "",
        newPassword: ""
      },
      rulePassword: {
        oldPassword: [
          { required: true, message: "请输入旧密码", trigger: "blur" }
        ],
        newPassword: [
          { required: true, message: "请输入新密码", trigger: "blur" }
        ]
      }
    };
  },
  components: {
    Pagetitle
  },
  methods: {
    btnFun() {},
    resetForm(name) {
      this.$refs[name].resetFields();
    },
    handleSubmitRegister(name) {
      this.$refs[name].validate(valid => {
        if (valid) {
          this.doRegister(name);
        }
      });
    },
    async doRegister(name) {
      const res = await register({
        oldPassword: this.updataPasswordData.oldPassword,
        newPassword: this.updataPasswordData.newPassword
      });
      if (res.status === 200) {
        this.resetForm(name);
        this.$Message.success("修改成功");
      } else {
        this.$Message.error(res.msg);
      }
    }
  }
};
</script>
<style lang="less" scoped>
@import "~@/styles/mixin";
.min-height {
  min-height: calc(78vh);
}
.password-box {
  margin-top: 100px;
}
</style>